package com.andro.inje.chansung.bus;

import java.util.List;

import com.andro.inje.chansung.R;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BusBasicAdapter extends BaseAdapter {

	private List<Bus> buses;
	private LayoutInflater inflater;
	private Activity activity;
	private ViewHolder viewHolder;
	
	public BusBasicAdapter(Activity activity, List<Bus> buses) {
		this.activity = activity;
		this.buses = buses;
		this.inflater = LayoutInflater.from(activity);
	}
	
	private class ViewHolder {
		public TextView destination;
		public TextView ticket;
		public TextView card;
	}
	
	public int getCount() {
		return buses.size();
	}

	public Bus getItem(int position) {
		return buses.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		
		if( view == null ) {
			viewHolder = new ViewHolder();
			view = inflater.inflate(R.layout.bus_time_check_cell_layout, null);
			viewHolder.destination = (TextView)view.findViewById(R.id.bus_time_check_cell_destination_tv);
			viewHolder.ticket = (TextView)view.findViewById(R.id.bus_time_check_cell_ticket_tv);
			viewHolder.card = (TextView)view.findViewById(R.id.bus_time_check_cell_card_tv);
			view.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder)view.getTag();
		}
		
		Bus bus = getItem(position);
		
		viewHolder.destination.setText(bus.getDestination());
		viewHolder.ticket.setText(bus.getTicketFare());
		viewHolder.card.setText(bus.getCardFare());
		
		return view;
	}

}
